package com.xgkj.diyiketang.activity.data;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xgkj.diyiketang.R;

/**
 * Created by windo on 16/8/3.
 */
public class GradeAdapter extends BaseAdapter{

    private Context mContext;
    private int mPosition = -1;
    private String[] mList;

    /**
     * @param type 1 科目
     *             2 年级
     *             3 排序
     * */
    public GradeAdapter(Context context) {
        mContext = context;
        mList = new String[]{"一年级","二年级","三年级","四年级","五年级","六年级","初一","初二","初三","高一","高二","高三","早教","幼儿园","综合"};
    }

    public void setSelectPosition(int position){
        mPosition = position;
    }

    @Override
    public int getCount() {
        if (mList != null){
            return mList.length;
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (mList != null) {
            return mList[position];
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView textView;
        if (convertView == null || convertView.getTag() == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.choose_item, null);
            textView = (TextView) convertView.findViewById(R.id.text);
            convertView.setTag(textView);
        }else {
            textView = (TextView) convertView.getTag();
        }
        textView.setText(mList[position]);
        if (position == mPosition){
            textView.setTextColor(mContext.getResources().getColor(R.color.shouye_tab_color_selected));
        }else {
            textView.setTextColor(mContext.getResources().getColor(R.color.detail_gray));
        }
        return convertView;
    }
}
